package com.joycessh.config;

import com.jagregory.shiro.freemarker.ShiroTags;
import com.joycessh.templates.HotsTemplate;
import com.joycessh.templates.PostsTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author Joycessh
 * @Description
 * @Date 8/20/19 12:00 PM
 */
@Configuration
public class FreemarkerConfig {

    @Autowired
    private freemarker.template.Configuration configuration;

    @Autowired
    ApplicationContext applicationContext;

    @PostConstruct
    public void setUp() {

        configuration.setSharedVariable("posts", applicationContext.getBean(PostsTemplate.class));
        configuration.setSharedVariable("hots", applicationContext.getBean(HotsTemplate.class));

        // shiro标签
        configuration.setSharedVariable("shiro", new ShiroTags());
    }
}
